using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace ScytheEngine
{
    public class Shader
    {
        #region Data Members

        private string m_Asset;
        private Effect m_Effect;

        #endregion

        #region Ctors

        public Shader(string asset)
        {
            m_Asset = asset;
        }
        #endregion

        #region Methods

        public void LoadContent(ContentManager loader)
        {
            m_Effect = loader.Load<Effect>(m_Asset);
        }

		internal void SetParameters(ScytheEngine.Object obj)
		{
			Matrix World =
				Matrix.CreateScale( obj.Scaling ) *
				Matrix.CreateFromQuaternion( obj.Rotation ) *
				Matrix.CreateTranslation( obj.Position );

			if(m_Effect.Parameters["WorldViewProject"] != null)
			{
				m_Effect.Parameters["WorldViewProject"].SetValue( World * CameraManager.ActiveCamera.View * CameraManager.ActiveCamera.Projection );
			}
			#region BasicEffect Support
			if ( m_Effect.Parameters["World"] != null )
			{
				m_Effect.Parameters["World"].SetValue( World );
			}
			if ( m_Effect.Parameters["View"] != null )
			{
				m_Effect.Parameters["View"].SetValue( CameraManager.ActiveCamera.View );
			}
			if ( m_Effect.Parameters["Projection"] != null )
			{
				m_Effect.Parameters["Projection"].SetValue( CameraManager.ActiveCamera.Projection );
			}
			#endregion
		}

        #endregion

        #region Properties

        public Effect Effect
        {
            get { return m_Effect; }
            set { m_Effect = value; }
        }

        #endregion
    }
}
